﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using RazakiBLL.Entities;

namespace RazakiBLL.Managers
{
    public class ApplicationPropertyRps : RpsRazaki<ApplicationProperty>
    {
        public ApplicationPropertyRps(ObjectContext context)
            : base(context)
        {
        }

        public void AddEditByPropertyName(string propertyName, string propertyValue)
        {
            var property = (from app in _objectSet
                            where app.PropertyName == propertyName
                            select app).FirstOrDefault();
            if (property == null)
            {
                property = new ApplicationProperty
                               {
                                   PropertyName = propertyName,
                                   PropertyValue = propertyValue,
                                   LastUpdatedDate = DateTime.Now
                               };
                Add(property);
            }
            else
            {
                property.PropertyValue = propertyValue;
                property.LastUpdatedDate = DateTime.Now;
            }
        }

        public string GetByPropertyName(string propertyName)
        {
            string result = string.Empty;
            var property = (from app in _objectSet
                            where app.PropertyName == propertyName
                            select app).FirstOrDefault();

            if (property != null)
            {
                result = property.PropertyValue;
            }

            return result;
        }
    }
}